package excel.study.controller;

import cn.afterturn.easypoi.excel.ExcelExportUtil;
import excel.study.test.ExcelUtil;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.multipart.MultipartFile;

import java.io.FileOutputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author 作者： chenMing
 * @DATE 创建时间： 2023/12/5 11:14
 * @Version 版本：cmBoot1.0
 */
@Controller
public class ExportController {

    @PostMapping("/importAssert")
    public void importAssertExcel(@RequestParam("file") MultipartFile file) throws Exception {
//        if (!file.isEmpty()) {
//            //获取原始的文件名
//            String originalFilename = file.getOriginalFilename();
//            //获取文件类型
//            String fileType = originalFilename.substring(originalFilename.lastIndexOf(".") + 1, originalFilename.length());
//            InputStream is = file.getInputStream();
//            List<String> title = Arrays.asList("ipaddr", "assertName", "assertGroupName", "assertType", "importantLevel",
//                    "macAddress", "operationName", "assertCategory", "manufacturer", "portServer", "department",
//                    "businessSys", "director", "phoneNum", "scanUpdate", "description");
//            List<Map<String, Object>> assets = ExcelUtil.parseExcel(title, is, fileType);
//            //调用 方法exportParams为设置的sheet页信息 list为拼装好的导出字段信息  jsonObjects为数据项
//            Workbook workbook = ExcelUtil.createExcel(title);
//            Sheet sheet = workbook.getSheetAt(0);
//            sheet.createFreezePane(0,0);
//            FileOutputStream fileOutputStream = new FileOutputStream("D:\\home\\excel\\test.xlsx");
//            workbook.write(fileOutputStream);
//            fileOutputStream.flush();
//            fileOutputStream.close();
//            workbook.close();
//        }
    }

}
